//
//  SegmentDropContainerController.m
//  MultiSegmentControl
//
//  Created by ET|冰琳 on 16/7/4.
//  Copyright © 2016年 Ice Butterfly. All rights reserved.
//

#import "SegmentDropContainerController.h"
#import "MultiCustomSegmentView.h"

@interface SegmentDropContainerController ()<MultiSegmentSplitViewDataSource, UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView     *seg;

@end

@implementation SegmentDropContainerController

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [UITableView new];
    [self.view addSubview:self.tableView];
    
    self.tableView.dataSource = self;
    self.tableView.delegate   = self;
    
    UIView *tableheader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    self.tableView.tableHeaderView = tableheader;
    tableheader.backgroundColor = [UIColor redColor];
    
    MultiCustomSegmentView *segmentView = [MultiCustomSegmentView segmentViewWithTitles:@[@"状态",@"类型"] andFrame:CGRectMake(0, 56,320, 44)];
    self.seg = segmentView;
    segmentView.dataSource = self;
    segmentView.dropContainer = self.view;
    
    [tableheader addSubview:segmentView];
    
//    [self.view addSubview:segmentView];
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.tableView.frame = self.view.bounds;
}

#pragma mark - UITableViewDelegate
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return  self.seg;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.textLabel.text = [NSString stringWithFormat:@"%@",indexPath];
    }
    return cell;
}

#pragma mark- MultiSegmentSplitViewDataSource
- (NSInteger)numberOfRowsInComponent:(NSInteger)component AtSegmentIndex:(NSInteger)segmentIndex{
    if(segmentIndex == 0){
        return 5;
    }else{
        return 2;
    }
}
- (void)didSelectAtSegmentIndex:(NSInteger)segmentIndex component:(NSInteger)component row:(NSInteger)row{
    
}

- (NSString *)titleForCellAtSegmentIndex:(NSInteger)segmentIndex component:(NSInteger)component row:(NSInteger)row{
    if (segmentIndex == 0) {
        NSArray *ary = @[@"等待付款",@"交易成功",@"未交易",@"发货中",@"服务中"];
        return ary[row];
    }else{
        NSArray *ary = @[@"状态1",@"状态2"];
        return ary[row];
    }
}

- (CGFloat)heightForSplitViewAtSegmentIndex:(NSInteger)segmentIndex{
    if (segmentIndex == 0) {
        return  5 * 44;
    }else{
        return 2 * 44;
    }
}


@end
